home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / cli / RemoveReturn.lha / RemoveReturn.c next >
Encoding:
C/C++ Source or Header  |  1998-03-07  |  1.6 KB  |  66 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.    int buf;
  7.    FILE *file, *fileII;
  8.  
  9.    if (argc > 1)
  10.    {
  11.       if ((file = fopen(argv[1], "r")) == NULL)
  12.       {
  13.          printf("Couldn't open the input text file...\n");
  14.          fclose(file);
  15.          exit(20);
  16.       }
  17.       if ((fileII = fopen("T:Temp.txt", "w")) == NULL)
  18.       {
  19.          printf("Couldn't open the Temporary text file...\n");
  20.          fclose(file);
  21.          fclose(fileII);
  22.          if (!remove("T:Temp.txt")) printf("Error removing temporary file...\n");
  23.          exit(20);
  24.       }
  25.       do
  26.       {
  27.          buf = getc(file);
  28.          if ((buf != EOF) && (buf != '\r')) putc(buf, fileII);
  29.       }
  30.       while (buf != EOF);
  31.       fclose(file);
  32.       fclose(fileII);
  33.  
  34.       if ((file = fopen(argv[1], "w")) == NULL)
  35.       {
  36.          printf("Couldn't reopen the input text file...\n");
  37.          fclose(file);
  38.          exit(20);
  39.       }
  40.       if ((fileII = fopen("T:Temp.txt", "r")) == NULL)
  41.       {
  42.          printf("Couldn't reopen the Temporary text file...\n");
  43.          fclose(file);
  44.          fclose(fileII);
  45.          if (!remove("T:Temp.txt")) printf("Error removing temporary file...\n");
  46.          exit(20);
  47.       }
  48.       do
  49.       {
  50.          buf = getc(fileII);
  51.          if (buf != EOF) putc(buf, file);
  52.       }
  53.       while (buf != EOF);
  54.       fclose(file);
  55.       fclose(fileII);
  56.  
  57.       if (!remove("T:Temp.txt"))
  58.       {
  59.          printf("Error removing temporary file...1\n");
  60.          exit(5);
  61.       }
  62.    }
  63.    else {printf("This Command has one argument: (textin)...\n"); exit(10);}
  64.    exit(0);
  65. }
  66.